import urllib
import urllib2
from pyquery import PyQuery as pq

arr_in, arr_not = ([],[])

def write_file():
    f2 = open('dm_in%s' % len(arr_in), 'wb')
    f2.write('\n'.join(arr_in))
    f2.close()

    f3 = open('dm_notin%s' % len(arr_not), 'wb')
    f3.write('\n'.join(arr_not))
    f3.close()

def catch():
    url = 'https://www.domainmonster.com/backorder/'
    f1 = open('dm-not')
    count = 0
    for count, line in enumerate(f1.readlines()):
        i = line.strip()
        content = urllib2.urlopen(url, urllib.urlencode({'q':i.split('.')[0], 'td':'.cc', 't':'16'}),).read()
        d = pq(content)
        if len(d('#boxes')):
            print 'yes: ', i
            arr_in.append(i)
        else:
            arr_not.append(i)
            print 'no:  ', i

        if(count%50==0):
            write_file()
    if(count%50!=0):
        write_file()

if __name__=='__main__':
    catch()

